﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BIExtAuth.Web
{
    public partial class Signin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblMsg.Text = Message;
        }
        private int ErrCode
        {
            get
            {
                string errCode = Request["errCode"];
                if (!string.IsNullOrEmpty(errCode))
                    return int.Parse(errCode);

                return 0;
            }
        }

        private string ErrMsg
        {
            get { return (Request["errMsg"] == null || Request["errMsg"] == "") ? "没有错误" : Request["errMsg"]; }
        }

        /// <summary>
        /// 登录错误消息
        /// </summary>
        private string Message
        {
            get
            {
                switch (ErrCode)
                {
                    case 0:
                        return string.Empty;
                    case -1:
                        return "用户名或密码不正确或用户被禁用！";
                    case -2:
                        return "用户名不存在！";
                    case -3:
                        return "OLAP用户登录失败！";
                    case -100:
                        return ErrMsg;
                    default:
                        return "用户登陆失败！";
                }
            }
        }

        private string ReturnUrl
        {
            get { return Request["ReturnUrl"]; }
        }

        /// <summary>
        /// 获取AnalyzerLoginAction URL
        /// </summary>
        private string AnalyzerLoginAction
        {
            get { return ConfigurationManager.AppSettings["AnalyzerLoginAction"]; }
        }

        protected string ActionUrl
        {
            get
            {
                string url = AnalyzerLoginAction;
                if (!string.IsNullOrEmpty(ReturnUrl))
                    url += string.Format("{0}ReturnUrl={1}",
                        url.Contains("?") ? "&" : "?",
                        Server.UrlEncode(ReturnUrl)
                        );

                return url;
            }
        }
    }
}